An aggregation function (also commonly known as a reduction function, reduce function, aggregator function, aggregation and aggregator), takes a collection of values of a specific type (e.g., type X) and produces a single value of specific type, possibly a different type (e.g., type Y). Aggregation functions are very common in mathematics, especially as functions that apply to sets. For example, a common aggregation function is a “count” function which produces a count of a number of values in a set. As an example, if a count function is passed the following set, {1,3,5,7}, the count function will return the value 4, because there are four values in the aforementioned set. As another example, if the count function is passed the following set, {Apple}, the count function will return the value 1, because there is one value in the aforementioned set. Finally, if the count function is passed the following set, { }, the count function will return the value 0, as there are no values in the aforementioned set.
While the above definition clearly states that the result of an aggregation is a single value, a resulting value may also be single value that contains many elements. For example, the result of an aggregation function may be a set, bag (i.e., a set which may contain duplicate values), map, function, or some other type of collection. As an example of such an aggregation function, the “odd” aggregation function produces a set containing “odd” values from a given set of values. For example, odd({1,2,3,4,5})={1,3,5}.
Aggregation functions may also be applied to bags, as opposed to sets. For example, the aggregation function, “distinct,” produces a set of distinct values contained within a bag (e.g., distinct([1,2,2,3,4,5,5])={1,2,3,4,5}. Other useful aggregation functions on bags and sets include: “min” (determining the minimum values in a collection), “max” (determining the maximum value in a collection), and “avg” (determining the average value in a collection).
One of the most advanced aggregation functions is the “group by” aggregation function. Its purpose is to group values into maps (often called tables). For example, where a system contains a collection of worldwide orders and an end-user requires the number of orders for each destination country, the system can provide a result represented using a group by aggregation function. Such a result could be presented as:
DestinationCountFrance2Germany1United Kingdom4United States4
Other aggregation functions may also be applied. Many software designers design computer systems which provide for such aggregation functions.